package com.sunk.fenbushishiwu.dtp.atomikos.service.impl;

import com.sunk.fenbushishiwu.dtp.atomikos.entity.CapitalAccount;
import com.sunk.fenbushishiwu.dtp.atomikos.entity.RedPacketAccount;
import com.sunk.fenbushishiwu.dtp.atomikos.mapper.xaAccountDBXML.CapitalAccountMapper;
import com.sunk.fenbushishiwu.dtp.atomikos.mapper.xaRedAccountDBXML.RedPacketAccountMapper;
import com.sunk.fenbushishiwu.dtp.atomikos.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
public class PayServiceImpl implements PayService {

    @Autowired
    CapitalAccountMapper capitalAccountMapper;
    @Autowired
    RedPacketAccountMapper redPacketAccountMapper;

    @Override
    @Transactional(rollbackOn = Exception.class)
    public void pay(int userId, int account, int redAccount) {
                  CapitalAccount ca=new CapitalAccount();
        ca.setUserId(userId);
        CapitalAccount capitalAccountDto=capitalAccountMapper.selectOne(ca);
        System.out.println(capitalAccountDto);
        RedPacketAccount red=new RedPacketAccount();
        red.setUserId(userId);
        RedPacketAccount redDto = redPacketAccountMapper.selectOne(red);
        System.out.println(redDto);

        //红包余额扣除
        redDto.setBalanceAmount(redDto.getBalanceAmount()-redAccount);
        redPacketAccountMapper.updateByPrimaryKey(redDto);

        System.out.println(0/0);

    }
}
